import React from 'react';
import $ from 'jquery';
import {
	Row,
	Col
} from 'antd';
import {
	ChartCard,
	MiniBar,
	Bar
} from "../../components/Charts";

export default class SalesChartShow extends React.Component {

	constructor(props) {
		super(props);

		this.state = {
			saleslist: []
		}
	}
	componentDidMount() {
		let url = 'http://127.0.0.1:8080/find';
		let datasource = [];
		$.getJSON(url, function(data) {
			for (var i = 0; i < data.length; i++) {
				var temp = {};
				temp.x = data[i].month;
				temp.y = data[i].sales;
				datasource = [...datasource, temp];
			}
			this.setState({
				saleslist: datasource
			});
		}.bind(this))
	}
	render() {
		return (
			<div>
				<Row gutter={16}>
				<Col span={24}>
					<ChartCard contentHeight={400}>
		          	<Bar height={400} title="销售图表" data={this.state.saleslist}/>  
		            </ChartCard>
				</Col>
				</Row>	          
	        </div>
		);
	}
}